package com.qy139.store.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qy139.entity.Room;
import com.qy139.store.service.IRoomService;
import com.qy139.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hjl
 * @since 2021-12-01
 */
@Api(tags = "自习室管理")
@RestController
@RequestMapping("/room")
public class RoomController {
    @Resource
    private IRoomService roomService;
    //关联查询
    @ApiOperation(notes = "两表联查分页模糊检索", value = "查询自习室")
    @GetMapping("/selectAll")
    public Result selectAll(Page<Room> page, @ApiParam("自习室名称") String rname){
        IPage<Room> page1 =roomService.selectAll(page,rname);
        return new Result(page1);
    }
    /*查全部*/
    @ApiOperation(notes = "供座位表的前端的下拉框使用", value = "查询自习室")
    @GetMapping("/findRoom")
    public Result findRoom(){
        return new Result(roomService.list());
    }
    /*唯一性校验*/
    @ApiOperation(notes = "对自习室的名字做唯一性校验，如果有该名称就不能新增或修改", value = "唯一性校验")
    @GetMapping("/checkName")
    public Result checkName(Room room){
        return roomService.selectName(room);
    }
    /*修改*/
    @ApiOperation(notes = "自习室的新增或修改", value = "修改自习室")
    @PostMapping("/updateRoom")
    public Result updateRoom(@RequestBody Room room){
       return roomService.addRoomOrUpdate(room);
    }
    /*修改状态*/
    @ApiOperation(notes = "修改自习室的状态", value = "修改状态")
    @PutMapping("/updateStatus")
    public Result updStatus(@RequestBody Room room){
      return roomService.updateSta(room);
    }
}

